//
//  RTLChainRequest.h
//  RTLNetWorking
//
//  Created by 林波 on 16/7/11.
//  Copyright © 2016年 linbo1. All rights reserved.

//  网络框架（链式请求:例如上一个请求的结果需要用在下个请求的参数上）

#import <Foundation/Foundation.h>
#import "RTLBaseRequest.h"

@class RTLChainRequest;


// 链式请求的代理
@protocol RTLChainRequestDelegate <NSObject>
@optional

/**
 *  请求成功
 *
 *  @param chainRequest 成功返回的信息
 */
- (void)chainRequestFinished:(RTLChainRequest *)chainRequest;


/**
 *  请求失败
 *
 *  @param chainRequest 失败的信息
 *  @param request      失败的强求
 */
- (void)chainRequestFailed:(RTLChainRequest *)chainRequest failedBaseRequest:(RTLBaseRequest*)request;

@end



/***********************************    回调设置   ***********************************/

typedef void (^RTLChainCallback)(RTLChainRequest *chainRequest, RTLBaseRequest *baseRequest);

@interface RTLChainRequest : NSObject

@property (nonatomic, strong, readonly) NSMutableArray *requests;
@property (weak, nonatomic) id<RTLChainRequestDelegate> delegate;

// 开始
- (void)start;

// 取消
- (void)cancel;

/**
 *  链式请求接口
 *
 *  @param request  请求的接口
 *  @param callback 链式回调
 */
- (void)addRequest:(RTLBaseRequest *)request callback:(RTLChainCallback)callback;


@end

@interface RTLChainRequestManager : NSObject


// 单例
+ (instancetype)sharedManager;

// 加入链式请求
- (void)addChainRequest:(RTLChainRequest *)chainRequest;

// 删除链式请求
- (void)removeChainRequest:(RTLChainRequest *)chainRequest;


@end
